/*package com.blb.util;

import net.sf.json.JSONObject;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MaYunUtil {
    *//*
    * 作用：码云第三方授权登录工具类
    * 作者：钟宇轩
    * *//*

    *//*测试主函数，运行正常则会返回一个json对象，对象内装有授权者相关信息*//*
    public static void main(String[] args) {
        String accessToken = getAccessToken("d6126d3f75bc7f4a56b53cebf9518476b7dd7ba702b439a36ef4dd43f87e8493");//这里要传入code才能试
        JSONObject object = getObject(accessToken);
        System.out.println(object);
    }

    *//*获取码云AccessToken的方法*//*
    public static String getAccessToken(String code) {
        *//*这里的code是步骤1中从码云服务器上获取的code*//*
        String result = ""; //返回的结果
        PrintWriter out = null;
        BufferedReader in = null;
        String access_token = null; //定义一个access_token空字符串
        String client_id = "f82d6527cdd1ad05d522d3777edd64442415f93b99f35950ab8a96f77bfc18af"; //client_id 此id为鲸鱼笔记在码云上的应用授权id
        String redirect_uri = "http://qjvcj3.natappfree.cc/certificate/mayuntest"; //回调地址，用于接收返回的json信息，与获取code的回调地址一致
        String client_secret = "5b1d7fad33b0ea6294239cb50fc78c11151d695681690488a0bf5e48e63359e8"; //同client_id
        String url = "https://gitee.com/oauth/token?grant_type=authorization_code&code=" + code +
                "&client_id=" + client_id + "&redirect_uri=" + redirect_uri + "&client_secret=" + client_secret;
        try {
            URL demo = new URL(url);//打开连接
            HttpsURLConnection conn = (HttpsURLConnection) demo.openConnection();
            *//*这一步很关键，伪造一个UA，用于排除访问403的错误，chrome要用本机的chrome版本信息*//*
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36)");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-type", "application/json;charset=UTF-8");
            *//*获取回调的信息*//*
            in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream())
            );
            *//*定义一个line存放回调的信息*//*
            String line;
            while ((line = in.readLine())!= null){
                result += line;
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {// 使用finally块来关闭输出流、输入流
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        *//*将返回的json转换为对象，获取其中的access_token*//*
        JSONObject jsonObject = JSONObject.fromObject(result);
        access_token = jsonObject.getString("access_token");
        return access_token;
    }

    *//*获取用户信息的方法*//*
    public static JSONObject getObject(String access_token) {
        JSONObject demoJson = null;
        String url = "https://gitee.com/api/v5/user?access_token=" + access_token; //access_token使用getAccessToken获取

        try {
            *//*打开连接*//*
            URL urlGet = new URL(url);
            HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
            http.setRequestMethod("GET"); // 必须是get方式请求
            http.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36)");
            http.setDoOutput(true);
            http.setDoInput(true);
            http.connect();
            InputStream is = http.getInputStream();
            int size = is.available();
            byte[] jsonBytes = new byte[size];
            is.read(jsonBytes);
            String message = new String(jsonBytes, "UTF-8");
            demoJson = JSONObject.fromObject(message);
            String id = demoJson.getString("id");
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        *//*返回的是用户信息*//*
        return demoJson;
    }
}*/
